package com.chat.service;

import com.chat.Local;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.common.User;
import com.chat.view.*;
import javafx.application.Platform;

import java.awt.*;

import static com.chat.view.MainWindowController.chat;
import static com.chat.view.MainWindowController.friend;
import static com.chat.view.VerifyMessageController.ver;
/*
  该类用于添加好友
 */
public class AddFriend {
    public void addfriend(String id,String addid){
        Message msg=new Message();
        User user=new User();
        user.setUsername(id);
        user.setAddid(addid);
        msg.setMesType(MessageType.MESSAGE_ADD_FRIEND);
        msg.setData(user);
        ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
        clientConnectServerThread.send(msg);
    }
    public void setfriend(User user){//将新好友加入到好友列表当中(接受端)
//        Platform.runLater(()-> {
//            ((javafx.scene.control.ListView) MainWindowView.$("listview")).getItems().clear();
//        });
//        friend.clear();
//        new GetFriendList(friend);
//        GetGroupList ggl=new GetGroupList();
//        ggl.getgrouplist();
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
               friend.add(new FriendListData(user.getNickname(),user.getUsername(),user.getQianming(),"1",user.getStatus()));
            }
        });
        Platform.runLater(()-> {
            ((javafx.scene.control.ListView) VerifyMessageView.$("verify")).getItems().clear();
        });
        ver.clear();
        GetVerifyMessage gvm=new GetVerifyMessage();
        gvm.getverifymeesage();
    }
    public  void setfriend1(){//发送端的添加好友
        Platform.runLater(()-> {
            ((javafx.scene.control.ListView) MainWindowView.$("listview")).getItems().clear();
        });
//        Platform.runLater(new Runnable() {
//            @Override
//            public void run() {
//
//            }
//        });
        friend.clear();
        new GetFriendList(friend);
        GetGroupList ggl=new GetGroupList();
        ggl.getgrouplist();
    }
}
